package com.dpj.wait_test;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.AlternatePrint")
public class AlternatePrint {
    static final Object lock=new Object();
    static boolean t2runned=false;
    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            synchronized (lock){
                while (!t2runned){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    log.debug("1");
                }
            }

        }, "t1");
        Thread t2 = new Thread(() -> {
            synchronized (lock){
                log.debug("2");
                t2runned=true;
                lock.notify();
            }

        }, "t2");
        t1.start();
        t2.start();
    }
}
